package com.maven.zh.util;

import java.util.UUID;

/**
 * 生成唯一的Id
 * */
public class GenerateUniqIdUtil {

	public static GenerateUniqIdUtil instance;
	public static GenerateUniqIdUtil getInstance(){
		if(instance==null){
			instance = new GenerateUniqIdUtil();
		}
		return instance;
	}
	//唯一的ID
	public int getGenerateUniqId(){
		synchronized(this){
			long time = System.nanoTime();
			String timeStamp = new StringBuffer().append(time).toString();
			return Integer.valueOf((timeStamp.substring(timeStamp.length()-7, timeStamp.length())));
		}
	}
	// 唯一的字符串
		public String getUUID() {
			synchronized (this) {
				String s = UUID.randomUUID().toString();
				// 去掉“-”符号
				return s.substring(1, 7);
			}

		}
	//唯一的字符串 充当MAC地址
	public  String getMacUUID() {
		synchronized(this){
			String s = UUID.randomUUID().toString();
			// 去掉“-”符号
			return  s.substring(9, 13) + s.substring(14, 18)+ s.substring(19, 23) + s.substring(24);
		}
	}

}
